import { Message } from 'element-ui'

const headers = {
    Token: localStorage.getItem('token')
}
const action =  'https://api.mingyangshuiwu.com/api/ad/Upload/Upload'

const imgType = ['image/jpeg', 'image/jpg', 'image/gif', 'image/png', 'image/bmp', 'image/svg']

const beforeUpload = (file) => {
    const isTypes = imgType.includes(file.type)
    const isLess = file.size / 1024 / 1024 < 5
    if (!isTypes) {
        Message.error('上传的文件格式不正确！')
    }
    if (!isLess) {
        Message.error('上传图片大小不能超过 5MB!')
    }
    return isTypes && isLess
}

export default function () {
    return [
        {
            action,
            headers,
            accept: imgType.join(','),
            imgType,
        },
        beforeUpload
    ]
}
